package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.mapper.RoomMapper;
import com.example.mybatisplus.model.dto.PageDTO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.RoomService;
import com.example.mybatisplus.model.domain.Room;
import com.example.mybatisplus.model.dto.BedInfoDTO;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2024-07-17
 * @version v1.0
 */
@RestController
@RequestMapping("/api/room")
public class RoomController {
    @Autowired
    private RoomService roomService;
    @GetMapping("pageList")
    public JsonResponse pageList(Room room, PageDTO dto){
        Page<Room> page=roomService.pageList(room,dto);
        return JsonResponse.success(page);

    }
//    @GetMapping("/list")
//    public JsonResponse<Page<Resident>> getResidentsByPage(
//            @RequestParam(name = "page", defaultValue = "1") Integer pageNum,
//            @RequestParam(name = "size", defaultValue = "10") Integer pageSize) {
//        Page<Resident> page = new Page<>(pageNum, pageSize);
//        roomService.page(page);
//        return JsonResponse.success(page);
//    }
    //修改床位信息
    @PostMapping("editRoom")
    public JsonResponse editRoom(@RequestBody Room room){
        boolean b=roomService.updateById(room);



        return JsonResponse.success(b);

    }
    @PostMapping("addRoom")
    public JsonResponse addRoom(@RequestBody Room room){
        boolean b = roomService.save(room); // 或者根据具体情况调用其他适合的方法进行保存操作
        return JsonResponse.success(b); // 返回操作是否成功的 JSON 响应
    }

//    @GetMapping("fenpei")
//    public List<Room> getRoomsEnabled() {
//        // 调用服务层方法获取符合条件的房间列表
//        return roomService.selectByIsEnableddetail(0); // 0 是示例的 isEnabled 的值
//    }
//    @Autowired
//    private RoomMapper roomMapper;
//
//    @GetMapping("disabled")
//    public JsonResponse pageList4(BedInfoDTO roomInfoDTO, PageDTO dto) {
//        Page<BedInfoDTO> page = roomService.getDisabledBed(roomInfoDTO, dto);
//        return JsonResponse.success(page);
//    }

    @PostMapping("removeRoom")
    public JsonResponse removeRoom(@RequestBody Room room){
        // res表示是否删除成功
        boolean res= roomService.removeRoom(room);
        // res.data
        return JsonResponse.success(res);
    }
    @PostMapping("forceRemoveRoom")
    public JsonResponse forceRemoveRoom(@RequestBody Room room){
        // res表示是否删除成功
        boolean res= roomService.forceRemoveRoom(room);
        // res.data
        return JsonResponse.success(res);
    }
}

